var  vm = new Vue({
    el:'#set',
    data:{
        user_id:'',
        user_name:'',
        city:'',
        web_token:'',
        content:'',
        tel:'',
        xhl_tel:''
    },
    methods:{
        // 提交意见和反馈
        submit:function () {
            var url = '/userweb/my/suggestion';
            var data = {
                // user_id:localStorage.getItem('user_id')
                user_id:1,
                content:this.content,
                tel:this.tel
            };
            var res = checkForm(data);
            if ( !res[ 'flag' ] ) {
                layer.msg( res[ 'msg' ] ,{
                    skin:'winning-class',
                    time:3000
                });
                return false;
            }
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    layer.msg('提交成功',{
                        skin:'winning-class',
                        time:3000
                    });
                    this.content = '';
                    this.tel = '';
                } else {
                    layer.msg(res.data.msg,{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }, function (res) {

            });
        },
        req:function () {
            var url = '/userweb/Homepage/xhlData';
            var data = {
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    this.xhl_tel    = res.data.xhlData.tel;
                    this.email      = res.data.xhlData.email;
                } else {
                    layer.msg(res.data.msg,{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }, function (res) {

            });
        }
    },
    mounted: function () {
        this.user_id        = localStorage.getItem('user_id');
        this.user_name      = localStorage.getItem('user_name');
        this.city           = localStorage.getItem('city');
        this.web_token      = localStorage.getItem('web_token');
        if (!this.user_id ){
           location.href = "/userweb/index/login.html";
        }
        this.req();
    }
});

// 检查表单
function checkForm(data) {
    var arr = [];
    if ( !data.content) {
        arr[ 'msg' ] = "请输入遇见的问题或建议！";
        arr[ 'flag' ] = false;
        return arr;
    }
    if ( data.content.length > 200 ) {
        arr[ 'msg' ] = "输入的字数超出200限制！";
        arr[ 'flag' ] = false;
        return arr;
    }
    arr[ 'flag' ] = true;
    return arr;
}
